package com.zxc.wordcount;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class WcReducer extends Reducer<LongWritable, Text, Text, IntWritable> {
    IntWritable v = new IntWritable();
    protected void reduce(Text key, Iterable<IntWritable> values, Reducer<LongWritable, Text, Text, IntWritable>.Context context) throws IOException, InterruptedException {
        int sum = 0;
        for (IntWritable value : values) {
            sum += value.get();
        }
        v.set(sum);

        // 写出
        context.write(key,v);
    }
}
